<?php
//PHP SCRIPT FOR METADATA EXTRACTION
require_once "bin/logger.php";

/**********************************************
  ********************************************
  ****      extra url information         ****
  ********************************************
***********************************************/

$socrata_urls = array("opendata.socrata.com", "data.eindhoven.nl");

global $RealDataSetLinksStart;
global $RealDataSetLinksEnd;

global $mink_session;



if(!function_exists('boolToString'))
{
    function boolToString($var)
    {
        return gettype($var) == "bool" ? "" : $var == "" ? "(nicks gevond)" : $var;
    }
}

if(!function_exists('remove_extra_breaks'))
{
    function remove_extra_breaks($var)
    {
        return trim(preg_replace(["/\s*\<br\>\s*/", "/\s*<br>\s*/"], [" ", " "], $var));
    }
}

if(!function_exists('boolToString'))
{
    function boolToString($var)
    {
        return gettype($var) == "bool" ? "" : $var == "" ? "(nicks gevond)" : $var;
    }
}
    
/**********************************************
  ********************************************
  ****            Socrata                 ****
  ********************************************
***********************************************/


if(preg_match("/socrata\.com/",$url_value, $matches) || checkIfExists($socrata_urls, $url_pre)){
	if(checkIfExists($socrata_urls, $url_pre))
	{
		ToDoLog()->info("php_scripts.php: Add to \$socrata_urls: $url_pre");
	}
	
	$socrata_url_array = array();
	
	preg_match("/\/([a-z0-9]{4}\-[a-z0-9]{4})\//", $url."/", $socrata_id);
	if(count($socrata_id) != 0)
	{
		addToArray($socrata_url_array, "https://".$url_pre."/api/views/".$socrata_id[1], true);
	}
	else
	{
		$url = preg_replace("/[?&]page=[0-9]*/","",  $url);
		$matches = getUrlQuery($url, "browse[?&]");//preg_match("/([".TextRegex()."]*)/", $url, $matches);
        if($matches != null)
            $url = "https://".$url_pre."/browse?".$matches."&page=";
        else
            $url = "https://".$url_pre."/browse?page=";
           
		preg_match("/\<div class\=\"resultCount\"\>\s*[a-zA-Z]*\s*[0-9]*\s*[a-zA-Z]*\s*([0-9]*)/", file_get_contents($url."1"), $pagesNo);
		for($j = 1; $j <= ceil(((int)$pagesNo[1])/10); $j++)
		{
			$url_extraction_data = file_get_contents($url.$j);
			//$url_extraction_data = $url_extraction_data[0];
			$split_url_data = explode("<tr itemscope=\"itemscope\" itemtype=\"http://schema.org/Dataset\" class=\"item collapsed  local\" data-viewId=\"", $url_extraction_data);
			for($i = 1; $i < count($split_url_data);$i++)
			{
				preg_match("/^([a-z0-9]{4}\-[a-z0-9]{4})/i", $split_url_data[$i], $socrata_id_split);
				$socrata_id = $socrata_id_split[0];
				if(!checkIfExists($links, "https://".$url_pre."/d/".$socrata_id))
					if(!$lookForNewLinks)
						array_push($socrata_url_array, "https://".$url_pre."/api/views/".$socrata_id);
			}
		}
	}
	foreach($socrata_url_array as $socrata_url)
	{
	    DataScraper::emptyData();
	    $socrata_id = explode("/", $socrata_url);
		$socrata_id = $socrata_id[count($socrata_id)-1];
		if(!(checkIfExists($links, "https://".$url_pre."/resource/".$socrata_id) && $lookForNewLinks))
		{
			$url_value = file_get_contents($socrata_url);
			$url_data = json_decode($url_value, TRUE);
			
			$dataset_url = "https://".$url_pre."/d/".$socrata_id."/";
			
			$dataset_type = 3;
			$dataset_update = 1;
	        $pass_check = true;
	        $childData = null;
			$protocol_split = explode(":/", $url);
$protocol_split_0 = $protocol_split[0];
			$protocol = $protocol_split_0 . ":";
			if(array_key_exists("attribution", $url_data))
		    	$organizationName = $url_data["attribution"];
		    else
		    {
		        $organizationName = "Unknown Organization";
		    }
	        if(array_key_exists("attributionLink", $url_data))
			    $organizationWebsite = $url_data["attributionLink"];
			$organizationContactPerson = $url_data["owner"]["displayName"];
			$organizationEmail = "Unknown@unknown.com";
			$dataset_update_time = 1;
			$dataset_type = 1;
			$blogTitle = $url_data["name"];
			
	        if(array_key_exists("description", $url_data))
	        {
	        	$blogExcerpt = substr($url_data["description"],0 , 200);
				if($blogExcerpt == false)
				    $blogExcerpt = "";
			    $blogContent = $url_data["description"];
			}
			$blogContent .= "<br>";
		    if(array_key_exists("rowsUpdatedAt", $url_data))
			$blogContent .=  "<br>" . "<b>Data was last updated at:</b> ". unixToDateTime($url_data["rowsUpdatedAt"]);
			if(array_key_exists("publicationDate", $url_data))
			$blogContent .=  "<br>" . "<b>Date of publication:</b> ". unixToDateTime($url_data["publicationDate"]);
			if(array_key_exists("viewCount", $url_data))
			$blogContent =  "<br>" . "<b>Times Viewed:</b> ". $url_data["viewCount"];
			
			if(array_key_exists("childViews", $url_data))
			{
			    $childData = json_decode(file_get_contents("https://".$url_pre."/api/views/".$url_data["childViews"][0]), true);
	            $blogContent .=  "<br>" . "<br><b>Columns in the Dataset</b>";
			    foreach($childData["columns"] as $row)
		        {
		            if(array_key_exists("top", $row["cachedContents"]))
		            {
			            $blogContent .= "<br>" . $row["name"] . "<br> ---  Largest: ". json_encode($row["cachedContents"]["largest"])."<br>  --- Smallest: " .json_encode($row["cachedContents"]["smallest"]);

		            }
		            else
		            {
			            $blogContent .= "<br>" . $row["name"];
		            }
		        }
		        $size = $url_data["blobFileSize"];
                foreach($childData["columns"] as $row)
		        {
		            if($row["id"] != -1)
		            {
    			        $firstRecord = null;
        		        if(array_key_exists(0, $url_data["columns"]))
        		            $firstRecord = $url_data["columns"][0]["cachedContents"];
        		        else
        		            $firstRecord = $childData["columns"][0]["cachedContents"];
        				$records = $firstRecord["non_null"] + $firstRecord["null"];
        				break;
		            }
		        }
		    }
			else
			{
			    if(count($url_data["columns"]) != 0)
			    {
			        $blogContent = "<br><br><b>Columns in the Dataset</b>";
			        foreach($url_data["columns"] as $row)
			        {
			            if(array_key_exists("top", $row["cachedContents"]))
			            {
			            	$blogContent .= "<br>" . $row["name"] . "<br> ---  Largest: ". json_encode($row["cachedContents"]["largest"])."<br>  --- Smallest: " .json_encode($row["cachedContents"]["smallest"]);
			            	/*if(gettype($row["cachedContents"]["largest"]) == "array")
			            	$blogContent .= "<br>" . $row["name"] . "<br> ---  Largest: ". json_encode($row["cachedContents"]["largest"])."<br>  --- Smallest: " .json_encod($row["cachedContents"]["smallest"]);
			            	else
		            		{
			            		$blogContent .= "<br>" . $row["name"] . "<br> ---  Largest: ".$row["cachedContents"]["largest"]."<br>  --- Smallest: " .$row["cachedContents"]["smallest"];
		            		}*/

			            }
			            else
			            {
				            $blogContent .= "<br>" . $row["name"];
			            }
			        }
			    }
			    $size = get_file_size("https://".$url_pre."/api/views/".$socrata_id."/rows.xml");
			    $firstRecord = null;
		        if(count($url_data["columns"]) != 0)
		            $records = $url_data["columns"][0]["cachedContents"]["non_null"] + $url_data["columns"][0]["cachedContents"]["null"];
		        else
		            $records = 0;
				
			}
			if(array_key_exists("category", $url_data))
				array_push($dataset_categories, $url_data["category"]);
			if(array_key_exists("tags", $url_data))
				$dataset_tags = $url_data["tags"];
			$file_types = array("CSV",
	            "JSON",
	            "PDF",
	            "RDF",
	            "RSS",
	            "XLS",
	            "XLSX",
	            "XML"
	        );
	        if($url_data["viewType"] == "geo")
	        {
		        addToArray($file_types, array("KML", "KMZ", "Shapefile", "ZIP"), true );
	        }
	        $blogContent = trim($blogContent, "<br>");
	        array_push($data_array, DataScraper::createData());
	    }
    }
}


/**********************************************
  ********************************************
  ****           AZURE DATASETS           ****
  ********************************************
***********************************************/

elseif(preg_match("/azure\.com/", $url)){

    $azure_id = null;
    preg_match("/datamarket\.azure\.com(\/dataset)?(.*)/", $url, $matches);
    preg_match_all("/(\/[a-zA-Z0-9\.]*)/", $matches[2], $azure_id);
    $urlcount = 0;
    foreach($links as $link)
    {
    	preg_match("/datamarket\.azure\.com(\/dataset)?(.*)/", $link, $links_check_1);
    	if(count($links_check_1) != 0)
        {
	        preg_match_all("/(\/[a-zA-Z0-9\.]*)/", $links_check_1[2], $links_check_2);
	        if(strtolower($links_check_2[1][0]) == strtolower($azure_id[1][0]) && strtolower($links_check_2[1][1]) == strtolower($azure_id[1][1]))
            	$urlcount++;
        }
        if($link == $url)
            break;
        if($urlcount == 2)
            break;
    }
    preg_match_all("/<collection href=\"([".TextRegex()."]*)\"\>\s*\<atom\:title\>/", $url_value, $azure_links);
    $checkIfAllExists = false;
    if(!$lookForNewLinks)
    {
        foreach($azure_links[1] as $azure_set)
        {
            if(!checkIfExists($links, "https://api.datamarket.azure.com".$azure_id[1][0] . $azure_id[1][1]."/v1/" . $azure_set))
            {
                $checkIfAllExists = true;
            }
        }
    }
    if(($urlcount != 2 && !$lookForNewLinks) || $checkIfAllExists)//replace with !$lookForNewLinks in the event the link needs to varified it doesnt exist before ||!($urlcount > 0 && $lookForNewLinks))
    {
        if($matches[1] != "/dataset")
        {
            $url_value = file_get_contents("https://datamarket.azure.com/dataset" . $azure_id[1][0] . $azure_id[1][1]);
        }
        preg_match("/Published by\:\<\/th\>\s*\<td\>\<a href\=\"([\w\/\.\:]*)\" target=\"_blank\" testid\=\"Publisher\"\>([a-zA-Z]*)/", $url_value, $matches);
        $data["organizationName"] = $matches[2];
        $data["organizationWebsite"] = $matches[1];
        preg_match("/\<\/title\>\s*\<meta content\=\"([".TextRegex()."]*) name\=\"description\" \/\>/", $url_value, $matches);
        $data["blogExcerpt"] = substr($matches[1], 0, 200);
        preg_match("/\<\/table\>\s*\<div class\=\"desc\"\>\s*\<p\>([".TextRegex()."\<\>]*)\<\/div\>\s*\<div id\=\"fb\-root\" class\=\"fbroot\"\>\s*\<p id\=\"FaceBookLikeParagraph\"\>\<\/p\>\s*\<\/div\>\s*\<\/div\>\s*\<\/div\>/", $url_value, $matches);
        $data["blogContent"] = $matches[1];
        preg_match_all("/\<a id\=\"\_ResRightLink\" target\=\"\_blank\" href\=\"http\:\/\/go\.microsoft[".TextRegex()."]*\"\>\<span\>([".TextRegex()."]*)\<\/span\>\<\/a\>\s*\<p\>/", $url_value, $matches);
        $data["file_types"] = $matches[1];
        preg_match("/\<p\>\<b\>Disclaimer\<\/b\>\<\/p\>\s*([".AllRegex()."]*)\s*\<\/div\>\s*\<\/section\>/", $url_value, $matches);
        $data["organizationDescription"] = $matches[1];
        preg_match_all("/\<a href\=\"\/browse\?Category\=([\s\w\<\>\=\"\&\;\.]*)>(.*)\<\/a\>\s*/", $url_value, $matches);
        $tags = array();
        foreach($matches[2] as $_tags)
        {
            $tags_split =  explode(",", $_tags);
            foreach($tags_split as $_tags_split)
            {
                $tags_split_2 =  explode(" and ", $_tags_split);
                if(count($tags_split_2) > 1)
                {
                    foreach($tags_split_2 as $_tags_split_2)
                    {
                        if(trim($_tags_split_2) != "")
                        {
                            addToArray($tags, trim($_tags_split_2), true);
                        }
                    }
                }
                else
                {
                    $tags_split_3 =  explode("&amp;", $_tags_split);
                    if(count($tags_split_3) > 1)
                    {
                        if(trim($tags_split_3[0]) == "")
                        {
                            if(trim($tags_split_3[1]) != "")
                            {
                                addToArray($tags, trim($tags_split_3[1]), true);
                            }
                        }
                        foreach($tags_split_3 as $_tags_split_3)
                        {
                            //next level
                            if(trim($_tags_split_3) != "")
                            {
                                addToArray($tags, trim($_tags_split_3), true);
                            }
                        }
                    }
                    else
                    {
                        if(trim($_tags_split) != "")
                        {
                            addToArray($tags, trim($_tags_split), true);
                        }
                    }
                }
                
            }
        }
        preg_match_all("/\<img alt\=\"Sample\&\#32\;Image\" src\=\"([".TextRegex()."]*)\" title\=\"Click\&/", $url_value, $matches);
        foreach($matches[1] as $img)
        {
            array_push($data["dataset_screenshot"],trim($img, "&#47;&#47;"));
        }
        $data["dataset_tags"] = $tags;
        $data["organizationEmail"] = "unknown@unknown.com";
        $data["protocol"] = "https:";
        $data["categories"] = "";
        $data["dataset_type"] = 3;
        $sub_data = file_get_contents("https://api.datamarket.azure.com".$azure_id[1][0] .$azure_id[1][1]."/v1/");
        preg_match_all("/\<collection href\=\"([a-zA-Z0-9\s]*)\"\>/",$sub_data, $matches);
        $url_title_info = str_replace(".", "\.", str_replace("/", "", $azure_id[1][0]));
        preg_match("/\<a href\=\"\/browse\/Data\?Publisher\=".$url_title_info."\"\>Data\<\/a\>\<\/li\>\s*\<li class\=\"active\"\>([a-zA-Z\s]*)/", $url_value, $title_info);
        foreach($matches[1] as $azure_set)
        {
            //final data
            $f_data = $data;
            $f_data["blogTitle"] = $title_info[1] . " ". $azure_set;
            $f_data["dataset_url"] = "https://api.datamarket.azure.com".$azure_id[1][0] . $azure_id[1][1]."/v1/" . $azure_set;
            $f_data["size"] = get_file_size($f_data["dataset_url"]);
            array_push($data_array, $f_data);
        }
    }
    $isRealScript = true;


}

/**********************************************
  ********************************************
  ****       DATA OVERHEID NL             ****
  ********************************************
***********************************************/

elseif($url_pre == "data.overheid.nl"){
    $url_array = array();
    if(preg_match("/dataset/", $url) == 0)
    {
        preg_match("/query=([a-zA-Z\-_]*)/", $url, $matches);
        $query = "";
        if(count($matches) != 0)
            $query = $matches[1];
        preg_match_all("/f\[[0-9]*\]\=([a-zA-Z0-9\-_\%\:\(\)]*)/", $url, $matches);
        $url = "https://data.overheid.nl/data/search?";
        foreach($matches[0] as $url_query)
        {
            $url = $url.$url_query."&";
        }
        if($query != "")
            $url = $url . "query=$query&page=";
        else
            $url .= "page=";
        preg_match("/([0-9]*) zoekresultaten\<\/div\>/", file_get_contents($url . "100000000"), $matches);
        $pagecount = ceil((((int)$matches[1])/20));
        for($i = 0; $i < $pagecount; $i++)
        {
            $url_value = file_get_contents($url.$i);
            preg_match("/\<div class\=\"list search_results\"\>([".AllRegex()."]*)\<div id\=\"search_results_bottom\"\>\<\/div\>/", $url_value, $matches);
            preg_match_all("/ \<h2 class\=\"views\-field views\-field\-title\"\>        \<a href\=\"([".TextRegex()."]*)\"\>/", $matches[1], $matches);
            foreach($matches[1] as $row)
            {
                array_push($url_array, "https://data.overheid.nl".$row);
            }
        }
    }
    else
    {
        if(!$lookForNewLinks)
            array_push($url_array, $url);
    }
    foreach($url_array as $url_row)
    {
        
        $matches = null;
        $metadata = null;
        $url_value = null;
        DataScraper::emptyData();
        $dataset_type = 1;
        $dataset_update_time = 6;
        if(preg_match("/json/", $url_row))
        {
            $url_value = file_get_contents(str_replace("json", "", trim($url_row, "/")));
        }
        else
        {
            $url_value = file_get_contents($url_row);
        }
        //preg_match("/\<meta http\-equiv\=\"cleartype\" content\=\"on\" \/\>([".AllRegex()."]*)\<title\>/", $url_value, $metadata);
        preg_match("/\<meta http\-equiv\=\"cleartype\" content\=\"on\" \/\>([".AllRegex()."]*)\<link rel\=\"shortcut icon\" href\=\"https\:\/\/data\.overheid\.nl\/sites\/data\.overheid\.nl\/files\/favicon\.ico\" type\=\"image\/vnd\.microsoft\.icon\" \/\>/", $url_value, $metadata);
        $metadata = $metadata[1];
        
        //extract url's
        $dataset_url = $url_row;
        preg_match_all("/\<meta property\=\"dcat\:accessURL\" content\=\"([".TextRegex()."]*)\" \/\>/", $metadata, $matches);
        $blogTitle_PRE = "";
        if(count($matches[1]) != 0)
        {	
            $blogContent .= $RealDataSetLinksStart."<br><br>REAL Data Set Links:";
            $valid_url_count = 0;
            $url_count = 0;
            $protocol_array = array();
            foreach($matches[1] as $row)
            {
                if(is_valid_url($row))
                {
                    $valid_url_count ++;
                }
                $url_count++;
                $blogContent .= "<br>$row";
                array_push($protocol_array, getProtocol($row));
            }
            $blogContent .= $RealDataSetLinksEnd;
            $protocol = get_most_occurances($protocol_array);
            if($url_count != $valid_url_count)
            {
                if($valid_url_count == 0)
                {
                    $blogTitle_PRE = "ALL LINKS DOWN";
                }
                else
                {
                    $blogTitle_PRE = "SOME LINKS DOWN";
                }
            }
            preg_match_all("/\<meta property\=\"dcat\:size\" content\=\"([".TextRegex()."]*)\" \/\>/", $metadata, $matches);
            $size = max($matches[1]);
            if($size == "0")
                $size = "1";
            else
            {
                $size = StringToBytes($size." mb");
            }
            preg_match_all("/\<meta property\=\"dcterms\:format\" content\=\"([".TextRegex()."]*)\" \/\>/", $metadata, $matches);
            if(preg_match("/ZIP(//", $matches[1]))
            {
                $matches[1] = preg_replace(array("/\(/", "/\)/"), array(",",","), $matches[1]);
            }
            foreach(preg_replace(array("/ en /", "/\|/", "/\:/", "/\//"), array(",", ",", ",", ","), $matches[1]) as $match_row)
            {
                foreach(trim_array(explode(",", $match_row), true) as $match_1_row)
                addToArray($file_types, $match_1_row, true);
            }
            $blogContent.="<br>";
        }
        $matches = null;
        
        preg_match("/\<meta property\=\"dcterms\:modified\" content\=\"([0-9\-]*)/", $metadata, $matches);
        if(count($matches) != 0)
            $blogContent.="<br>Date Last Modified: " . $matches[1];
        
        $matches = null;
        preg_match("/\<meta property\=\"dcterms\:temporal\" content\=\"start\=([0-9\-]*);end=([0-9\-]*)/", $metadata, $matches);
        if(count($matches) != 0)
            $blogContent.="<br>Date research was conducted: " . $matches[1]. " - " . $matches[2];
            
        $matches = null;
        preg_match("/\<meta property\=\"overheiddata\:linked_open_data_stars\" content\=\"([0-9])/", $metadata, $matches);
        if(count($matches) != 0)
        {
            $linknum = (int)$matches[1];
            $extraMetadataDetails = $extraMetadataDetails . "<br><b>Type of Data</b>: ";
        }
        else
        {
            $linknum = 0;
        }
        if($linknum == 1)
        {
        	$extraMetadataDetails = $extraMetadataDetails . "Online; open licentie";
        }
        else if($linknum == 2)
        {
            $extraMetadataDetails = $extraMetadataDetails . "Gestructureerde data";
        }
        else if($linknum == 3)
        {
            $extraMetadataDetails = $extraMetadataDetails . "In een open formaat";
        }
        else if($linknum == 4)
        {
            $extraMetadataDetails = $extraMetadataDetails . "RDF en SPARQL";
        }
        
        $matches = null;
        preg_match("/\<meta property\=\"overheiddata\:maintainer_email\" content\=\"([".TextRegex()."]*)\"\s*\/\>/", $metadata, $matches);
        if(count($matches) != 0)
            if($matches[1] != "")
                $organizationEmail  = $matches[1];
        if($organizationEmail == "+_!@#&*#requiredText")
            $organizationEmail = "unknown@unknown.com";
        
        $matches = null;
        preg_match("/\<meta property\=\"dcterms\:title\" content\=\"([".TextRegex()."]*)\"\s*\/\>/", $metadata, $matches);
        if(count($matches) != 0)
            $blogTitle = $matches[1];
        else
            $blogTitle = "No Blog Title";
            
        
        
        $matches = null;
        preg_match("/\<meta property\=\"dcterms\:description\" content\=\"([".TextRegex()."]*)\"\s*\/\>/", $metadata, $matches);
        $blogContent = $matches[1] . $blogContent;
        $blogExcerpt = substr($matches[1], 0, 200);
        
        $matches = null;
        preg_match("/\<meta property\=\"dcterms\:subject\" content\=\"([".TextRegex()."]*)\"\s*\/\>/", $metadata, $matches);
        $dataset_tags = trim_array(explode(", ", $matches[1]));
        
        $matches = null;
        preg_match("/\<link rel\=\"DCTERMS\.license\" href\=\"[".TextRegex()."]*\" title\=\"([".TextRegex()."]*)\"\s*\/\>/", $metadata, $matches);
        if(count($matches) != 0)
            $extraMetadataDetails .= "<br><b>License</b>: " . $matches[1];
        //EXTRA METADATA DATA
        preg_match("/involved\-organisations\-table\"\>\s*\<caption\>Betrokken organisaties\<\/caption\>\s*\<tbody\>([".AllRegex()."]*)/", $url_value, $matches);
        preg_match_all("/\<tr class\=\"[a-z]*\"\>\<th\>[".TextRegex()."]*\<\/th\>\<td\>\s*([".TextRegex()."]*)\s*/", $matches[1], $matches);
        $matches = trim_array($matches[1]);
        
        $matchCount = 0;
        while($organizationName == "+_!@#&*#requiredText")
        {
            if($matches[$matchCount] != "")
            {
                $organizationName = $matches[$matchCount];
            }
            else
            {
                $matchCount += 2;
            }
            if($matchCount == 6)
            {
                $matchCount = 1;
            }
            elseif($matchCount == 7)
            {
                break;
            }
        }
        if($organizationName == "+_!@#&*#requiredText")
            $organizationName = "No Organization Name";
        $orgData = array();
        $matchCount+=2;
        while($matchCount < 7)
        {
            if($matches[$matchCount] != "")
            {
                if($organizationDescription == "")
                {
                    $organizationDescription = "Additional Organization/People Involved: ";
                }
                $orgCount = count($orgData);
                addToArray($orgData, strtolower($matches[$matchCount]), true);
                if($orgCount < count($orgData))
                    $organizationDescription .= "<br>".$matches[$matchCount];
                $matchCount+=2;
            }
            else
            {
                $matchCount += 2;
            }
            if($matchCount == 6)
            {
                $matchCount = 1;
            }
        }
        
        $matches = null;
        preg_match("/\<meta property\=\"dcterms\.provenance\" content\=\"([".TextRegex()."]*)\"\s*\/\>/", $metadata, $matches);
        if(count($matches) != 0)
            $blogContent .= "<br>NGR ID: ".$matches[1];
        
        $matches = null;
        preg_match("/\<link rel\=\"DCTERMS\.license\" href\=\"[".TextRegex()."]*\" title\=\"([".TextRegex()."]*)\" \/\>/", $metadata, $matches);
        if(count($matches) != 0)
            $blogContent.= "<br>License of Dataset: ".$matches[1];
        
        $matches = null;
        preg_match("/\<meta property\=\"overheiddata\:url\" content\=\"([".TextRegex()."]*)\"\s*\/\>/", $metadata, $matches);
        if(count($matches) != 0)
            $blogContent.= "<br>More Information on dataset: <a href=\"".$matches[1]. "\">".$matches[1]."</a>";
        $extraMetadataDetails = "Extra Metadata Details: " . $extraMetadataDetails;
        if($blogTitle_PRE != "")
        	$blogContent .= $blogContent_PRE . "<br><br>";
        array_push($data_array, DataScraper::createData());
        
    }
}



/**********************************************
  ********************************************
  ****     nationaalgeoregister.nl        ****
  ********************************************
***********************************************/


elseif(preg_replace("/www\./", "", $url_pre) == "nationaalgeoregister.nl") {
 
	$url_check = explode("keyword", $url);
	$ngr_urls = array();
	
	if(preg_match("/from\=/", $url_check[0]) == 1)
    {
		$mink_session->visit($url);		
		$ngr_urls = array();
		$numberOfLinks = 1;
		for($i = 0; $i < $numberOfLinks; $i++)
		{
			for($j = 0; $j < 6; $j++)
			{
				if(preg_match_all("/javascript\:void\(catalogue\.metadataShow\(\'([".TextRegex()."]*)\'\)\);\"\>/", $mink_session->getPage()->getContent(), $matches) != 0)
					break;
				$mink_session->wait(5000);
			}
			addToArray($ngr_urls, $matches[1]);
			if($i == 0)
			{
				preg_match("/resultaat\(en\)\s*\/\s*([0-9]*)/", $mink_session->getPage()->getContent(), $matches);
				$numberOfLinks = ceil((((int)$matches[1])/50));
			}
			if($numberOfLinks != 1)
				$mink_session->getPage()->findById("ext-gen391")->click();
		}
	}
	else
	{
		$ngr_id = explode("|", $url);
		if(count($ngr_id) != 1)
		{
			preg_match("/([a-zA-Z0-9\-]*)/", $ngr_id[1], $matches);
			array_push($ngr_urls, $matches[1]);
		}
		else
		{
			$ngr_id = explode("?uuid=", $url);
			
			array_push($ngr_urls, $ngr_id[1]);
		}
    }
	foreach($ngr_urls as $url_row)
	{
		DataScraper::emptyData();
		$dataset_url = "http://www.nationaalgeoregister.nl/geonetwork/srv/search/?uuid=".$url_row;
		$mink_session->visit($dataset_url);
		
		$count_one = count(str_split($mink_session->getPage()->getContent()));
		$count_two = 0;
		$count_check = 0;
		sleep(2);
		while(!($count_one == $count_two && $count_check == 6))
		{
			$count_two = $count_one;
			$count_one = count(str_split($mink_session->getPage()->getContent()));
			if($count_one == $count_two)
			{
				$count_check++; 
			}
			else
			{
				$count_check = 0;
			}
			sleep(0.5);
		}
		
		$url_value = $mink_session->getPage()->getContent();
		
		$matches = null;
		preg_match('/\<meta name\=\"og\:title\" content\=\"(['.TextRegex().']*)\"\s?\/?\>/', $url_value, $matches);
		if(count($matches) != 0 && $matches != null)
	    {
	        $blogTitle = $matches[1];
	    }
	    //out($matches);
	    
	    $matches = null;
		preg_match('/\<meta name=\"subject\"\s*content\=\"(['.TextRegex().']*)\"\s?\/?\>/', $url_value, $matches);
		if(count($matches) != 0 && $matches != null)
	    {
	        $blogContent = $matches[1];
		    $blogExcerpt = substr($blogContent, 0, 200);
	    }
	    //out($matches);
	    
	    $matches = null;
	    preg_match("/Taal van de bron\<\/th\>\<td\>([".TextRegex()."]*)/", $url_value, $matches);
	    if(count($matches) != 0 || $matches != null)
	    {
	        $blogContent .= "<br><br>Source Language: " . $matches[1];
	    }
	    //out($matches);
	    
	    $matches = null;
		preg_match_all("/gmd\:CI\_OnlineResource\|gmd\:onLine\|gmd\:MD_Metadata[".TextRegex()."]*\>\s*\<label for\=\"_\"\>Online bronnen\<\/label\>..\s*\<\/th\>\s*\<td\>\<a target\=\"_new\" href\=\"([".TextRegex()."]*)\"\>/", $url_value, $matches);
		if(count($matches) != 0 && $matches != null)
	    {
	        $blogContent .= "<br><br>Dataset Url(s):";
	        $blogContent .= $RealDataSetLinksStart;
	        for($i = 0; $i < count($matches[1]); $i++)
	        {
	            $blogContent .= "<br>".$matches[1][$i];
	        }
	        $blogContent .= $RealDataSetLinksEnd;
	        $blogContent .= "<br>(if it doesn't work, go to NGR site, data will be accessible there)";
	    }
	    //out($matches[1]);
	    
	    $matches = null;
		preg_match_all("/\<meta name\=\"keywords\" content\=\"([".TextRegex()."]*)\"\s?\/?\>/", $url_value, $matches);
		foreach($matches[1] as $match_row)
		{
			if(count($matches) != 0 && $matches != null)
		    {
		        addToArray($dataset_tags,trim_array(explode(", ", $match_row), true));
		    }
	    }
	    //out($matches);
	    
	    $matches = null;
	    preg_match_all("/([a-zA-Z0-9\-\s]*)\-coordinaat\<\/span\>\<\/b\>\<br \/\>\<input type\=\"number\" size\=\"[0-9]*\" readonly\=\"readonly\" value\=\"([0-9a-zA-Z\.]*)\" id\=\"[0-9a-zA-Z\.]*\" class\=\"md\" \/\>/", $url_value, $matches);
	    if(count($matches) != 0 || $matches != null)
	    {
		    $blogContent .= "<br><br>Area data is encapsulated within: <br>Min X-Coordinate:" . $matches[2][1];
	        $blogContent .= "<br>Min Y-Coordinate:" . $matches[2][3];
	        $blogContent .= "<br>Max X-Coordinate:" . $matches[2][2];
	        $blogContent .= "<br>Max Y-Coordinate:" . $matches[2][0];
	    }
	    //out($matches);
	    
	    $matches = null;
	    preg_match("/Ruimtelijk schema\<\/th\>\<td\>\<b\>[".TextRegex()."]*\<\/b\>\:([".TextRegex()."]*)/", $url_value, $matches);
	    if(count($matches) != 0 && $matches != null)
	    {
	        $blogContent .= "<br><br>Data Type: ".remove_extra_breaks($matches[1]);
	    }
	    //out($matches);
	    	    
	    $matches = null;
	    preg_match("/Datum van de bron\<\/label\>..\s*\<\/th\>\s*\<td\>([0-9\-]*)\s*\<\/td\>\s*\<\/tr\>\s*\<tr class\=\"([a-z]*)/", $url_value, $matches);
        if(count($matches) != 0 && $matches != null){
	        $blogContent .= "<br><br>Datum of ".$matches[2].": " . $matches[1];
	    }
	    //out($matches);
	    
	    $matches = null;
	    preg_match("/Metadata change date\s*([0-9\-]*)/", $url_value, $matches);
	    if(count($matches) != 0 && $matches != null){
		    $blogContent .= "<br>Date of change in Metadata: " . $matches[1];
	    }
	    //out($matches);
	    	    
	    $matches = null;
	    preg_match_all("/(begin|time|end)Position\|\"\>\<label for\=\"_\"\>((Begin|Eind)?datum)\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/i", $url_value, $matches);
		if(count($matches) != 0 || $matches != null)
	    {
	    	$blogContent .= "<br><br>Date range of data";
	    	for($i = 0; $i < count($matches[2]); $i++)
	    	{
		    	$blogContent .= "<br>".$matches[2][$i].": ".$matches[4][$i];
	    	}
	    }
	    //out($matches);
	    
	    
	    $matches = null;
	    preg_match("/Algemene beschrijving herkomst\s*\**\s*\<\/label\>\s*\<div\>([".TextRegex()."]*)/", $url_value, $matches);
	    if(count($matches) != 0 && $matches != null)
	    {
	        $blogContent .= "<br><br>General Description of Origin: " . trim($matches[1]);
	    } 
	    //out($matches);
	    
	    $matches = null;
	    preg_match_all('/lightbox\-viewset\"\>\<img title\=\"['.TextRegex().']*\" alt\=\"['.TextRegex().']*\" src\=\"(['.TextRegex().']*)\" class\=\"['.TextRegex().']*\" \/\>/', $url_value, $matches);
	    if(count($matches) != 0 || $matches != null)
	    {
	    	foreach($matches[1] as $screenshot_url)
	    	{
	    		if(is_valid_url($screenshot_url))
	    			array_push($dataset_screenshot, $matches[1]);
	    		elseif(is_valid_url("http://www.nationaalgeoregister.nl".$screenshot_url))
	    			array_push($dataset_screenshot, $matches[1]);
	    		else
	    			array_push($dataset_screenshot, $matches[1]);
	    	}
	    }
	    //out($matches);
	    
	    
	    preg_match("/Online bronnen\<\/label\>..\s*\<\/th\>\s*\<td\>\<a target\=\"_new\" href\=\"[".TextRegex()."]*\>([".TextRegex()."]*)/", $url_value, $matches);
	    if(count($matches) != 0)
	    {
		    $organizationWebsite = $matches[1];
	    }
	    
	    
	    //CONTACT INFORMATION
	    $organizationDescription = "Data Pertaining to the Organization, Data Provider, or Metadata Provider::<br>";
	    $first_contact_info_all = explode("Contactgegevens voor de data</span>", $url_value);
	    for($i = 1; $i < count($first_contact_info_all); $i++)
	    {
		    $first_contact_info = preg_replace("/\<\/table\>\s*\<\/fieldset\>\s*\<\/td\>\s*\<\/tr\>\s*\<\/tbody\>\s*\<\/table\>\s*\<\/td\>\s*\<\/tr\>\s*\<\/tbody\>\s*\<\/table\>\s*\<\/fieldset\>\s*\<\/td\>\s*\<\/tr\>([".AllRegex()."]*)/", "", $first_contact_info_all[$i]);
		    
		    $matches = null;
		    preg_match("/Naam Contactpersoon( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	$organizationDescription .= "<br>Name of Contact Person: ".$matches[2];
				if($organizationContactPerson == "")
			    {
				    $organizationContactPerson = $matches[2];
			    }
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Verantwoordelijke organisatie bron( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	if($organizationName == "+_!@#&*#requiredText")
			    {
				    $organizationName = $matches[2];
			    }
			    $organizationDescription .= "<br>Organization Whence Data Is From: ".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Rol contactpersoon( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>Person's Role: ".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Telefoon( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	if($i == 1)
			    {
				    $organizationPhoneNumber = $matches[2];
			    }
			    $organizationDescription .= "<br>Phone Number: ".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Fax( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>Fax Number: ".$matches[2];
		    }
		    //out($matches);
		    
		    $organizationDescription .= "<br>Address:";
		    
		    $matches = null;
		    preg_match("/Adres( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Plaats( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Provincie( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Postcode( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Land( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    if(substr($organizationDescription, -14) == "<br>Address:")
		    {
			    $organizationDescription = substr($organizationDescription, strlen($organizationDescription)-14);
		    }
		    
		    $matches = null;
		    preg_match("/E-mail( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>\<[".TextRegex()."]*\>\s*([".TextRegex()."]*)/", $first_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	if($organizationEmail == "+_!@#&*#requiredText")
		    		$organizationEmail = $matches[2];
			    $organizationDescription .= "<br>E-mail: ".$matches[2];
		    }
		    //out($matches);
	    }
	    
	    $second_contact_info_all = explode("Partijen verantwoordelijk voor de metadata", $url_value);
	    for($i = 1; $i < count($second_contact_info_all); $i++)
	    {
		    $second_contact_info = preg_replace("/\<\/table\>\s*\<\/fieldset\>\s*\<\/td\>\s*\<\/tr\>\s*\<\/tbody\>\s*\<\/table\>\s*\<\/td\>\s*\<\/tr\>\s*\<\/tbody\>\s*\<\/table\>\s*\<\/fieldset\>\s*\<\/td\>\s*\<\/tr\>([".AllRegex()."]*)/", "", $second_contact_info_all[$i]);
		    
		    $matches = null;
		    preg_match("/Naam Contactpersoon( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	$organizationDescription .= "<br>Name of Contact Person: ".$matches[2];
				if($organizationContactPerson == "")
			    {
				    $organizationContactPerson = $matches[2];
			    }
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Verantwoordelijke organisatie (bron|metadata)( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	if($organizationName == "+_!@#&*#requiredText")
			    {
				    $organizationName = $matches[3];
			    }
			    $organizationDescription .= "<br>Organization Whence Data Is From: ".$matches[3];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Rol contactpersoon( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>Person's Role: ".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Telefoon( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	if($i == 1)
			    {
				    $organizationPhoneNumber = $matches[2];
			    }
			    $organizationDescription .= "<br>Phone Number: ".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Fax( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>Fax Number: ".$matches[2];
		    }
		    //out($matches);
		    
		    $organizationDescription .= "<br>Address:";
		    
		    $matches = null;
		    preg_match("/Adres( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Plaats( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Provincie( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Postcode( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    $matches = null;
		    preg_match("/Land( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
			    $organizationDescription .= "<br>".$matches[2];
		    }
		    //out($matches);
		    
		    if(substr($organizationDescription, -14) == "<br>Address:")
		    {
			    $organizationDescription = substr($organizationDescription, strlen($organizationDescription)-14);
		    }
		    
		    
		    $matches = null;
		    preg_match("/E-mail( \*)?\<\/label\>..\s*\<\/th\>\s*\<td\>\<[".TextRegex()."]*\>\s*([".TextRegex()."]*)/", $second_contact_info, $matches);
		    if(count($matches) != 0)
		    {
		    	if($organizationEmail == "+_!@#&*#requiredText")
		    		$organizationEmail = $matches[2];
			    $organizationDescription .= "<br>E-mail: ".$matches[2];
		    }
		    //out($matches);

		}	    
	    
	    //LEGAL INFO AT ENDING
	    $legal_url_value = str_replace("<br />", "", $url_value);
	    $extraMetadataDetails = "Dataset Constraints";
	    $matches = null;
	    $legal_info_1 = explode("</div>Beperkingen</span>", $legal_url_value);
		for($i = 1; $i < count($legal_info_1); $i++)
		{
			$legal_info = null;
			$legal_info = preg_replace("/\<\/tr\>\s*\<\/tbody\>\s*\<\/table\>\s*\<\/fieldset\>\s*\<\/td\>\s*\<\/tr\>([".AllRegex()."]*)/", "", $legal_info_1[$i]);
			if($legal_info != null)
			{
				$matches = null;
				preg_match_all("/([a-zA-Z\(\)\s\*]*)\<\/label\>..\s*\<\/th\>\s*\<td\>(\<[".TextRegex()."]*\>)?([".TextRegex()."]*)(\<\/(a|b)\>)?([".TextRegex()."]*)/", $legal_info, $matches);
				if(count($matches[0]) != 0 || $matches != null)
				{
					$extraMetadataDetails .= "<br><br>Constraints:";
					for($j = 0; $j < count($matches[0]); $j++)
					{
						$extraMetadataDetails .= "<br>".remove_extra_breaks($matches[1][$j]).":: ". remove_extra_breaks($matches[3][$j]);
					}
				}
			}
			
		}
	    
	    $matches = null;
	    $legal_info_2 = explode("</div>Legale beperkingen</span>", $legal_url_value);
	    //Output($legal_info_1[1]);
		for($i = 1; $i < count($legal_info_2); $i++)
		{
			$legal_info = null;
			$legal_info = preg_replace("/\<\/tr\>\s*\<\/tbody\>\s*\<\/table\>\s*\<\/fieldset\>\s*\<\/td\>\s*\<\/tr\>([".AllRegex()."]*)/", "", $legal_info_2[$i]);
			if($legal_info != null)
			{
				$matches = null;
				preg_match_all("/([a-zA-Z\(\)\s\*]*)\<\/label\>..\s*\<\/th\>\s*\<td\>(\<[".TextRegex()."]*\>)?([".TextRegex()."]*)(\<\/(a|b)\>)?([".TextRegex()."]*)/", $legal_info, $matches);
				if(count($matches[0]) != 0 || $matches != null)
				{
					$extraMetadataDetails .= "<br><br>Legal Constraints:";
					for($j = 0; $j < count($matches[0]); $j++)
					{
						$extraMetadataDetails .= "<br>".remove_extra_breaks($matches[1][$j]).":: ". remove_extra_breaks($matches[3][$j]).remove_extra_breaks($matches[6][$j]);
					}
				}
			}
			
		}
		
		$matches = null;
	    $legal_info_3 = explode("</div>Veiligheidsrestricties </span>", $legal_url_value);
		for($i = 1; $i < count($legal_info_3); $i++)
		{
			$legal_info = null;
			$legal_info = preg_replace("/\<\/tr\>\s*\<\/tbody\>\s*\<\/table\>\s*\<\/fieldset\>\s*\<\/td\>\s*\<\/tr\>([".AllRegex()."]*)/", "", $legal_info_3[$i]);
			if($legal_info != null)
			{
				$matches = null;
				preg_match_all("/([a-zA-Z\(\)\s\*]*)\<\/label\>..\s*\<\/th\>\s*\<td\>(\<[".TextRegex()."]*\>)?([".TextRegex()."]*)(\<\/(a|b)\>)?([".TextRegex()."]*)/", $legal_info, $matches);
				//Output($matches);
				if(count($matches[0]) != 0 || $matches != null)
				{
					$extraMetadataDetails .= "<br><br>Security Constraints:";
					for($j = 0; $j < count($matches[0]); $j++)
					{
						$extraMetadataDetails .= "<br>".remove_extra_breaks($matches[1][$j]).":: ". remove_extra_breaks($matches[3][$j]).remove_extra_breaks($matches[6][$j]);
					}
				}
			}
			
		}
		
		
		$file_types = array("xml");
	    
	    $organizationDescription = preg_replace(["/^\s*/","/\s*$/"], ["",""],$organizationDescription);
	    $blogContent = preg_replace(["/^\s*/","/\s*$/"], ["",""],$blogContent);
	    
	    array_push($data_array, DataScraper::createData()); 
	}
}




/**********************************************
  ********************************************
  ****      MetaData.Brabant.nl           ****
  ********************************************
***********************************************/


elseif(false) {
    //http://metadata.brabant.nl/index.php/Speciaal:GridwalkerSearch?q=%22eindhoven%22
    $url_data_array = array();
    if(preg_match("/Speciaal\:GridwalkerSearch/", $url))
    {
        $url_query = getUrlQuery($url, "Speciaal\:GridwalkerSearch\?");
        $url = "http://metadata.brabant.nl/index.php/Speciaal:GridwalkerSearch?". ($url_query != null ? $url_query."&page=" : "page=");
        preg_match("/([0-9]*) resultaten\s*\<\/div\>\s*\<div id\=\"gw\-pager\-sorter\"\>/", $url_value, $pageCount);
        for($i = 1; $i <= ceil((int)$pageCount[1]/20); $i++)
        {
            $url_value = file_get_contents($url . $i);
            preg_match_all("/\<a class\=\"search\-title\" href\=\"([".TextRegex()."]*)\">/", $url_value, $matches);
            foreach($matches[1] as $row)
            {
                preg_match("/([a-zA-Z0-9_\.\%]*)\)$/", $row, $row_match);
                array_push($url_data_array, "http://metadata.brabant.nl/metadata/" .str_replace("%20", "_", $row_match[1]). ".xml");
                
            }
        }
    }
    else
    {
        array_push($url_data_array, $url);
    }
    
    foreach($url_data_array as $url_row)
    {
        $url_value = simplexml_load_file($url_row);//file_get_contents($url_row);
        
		Output(var_dump(json_decode(json_encode($url_value), true)));
        preg_match("/([".TextRegex()."]*)\<\/gco\:CharacterString\>\<\/title\>\<alternateTitle\>/", $url_value, $matches);
        $blogTitle = $matches[1];
        
        preg_match("/([".TextRegex()."]*)\<\/gco\:CharacterString\>\<\/abstract\>/", $url_value, $matches);
        $blogContent .= $matches[1] . $blogContent."<br>";
        preg_match("/\<purpose xmlns\:gco\=\"http\:\/\/www\.isotc211\.org\/2005\/gco\" xmlns\:def\=\"http\:\/\/www\.isotc211\.org\/2005\/gmd\"\>\<gco\:CharacterString xmlns\:gml\=\"http\:\/\/www\.opengis\.net\/gml\" xmlns\:xlink\=\"http\:\/\/www\.w3\.org\/1999\/xlink\" xmlns\:xsi\=\"http\:\/\/www\.w3\.org\/2001\/XMLSchema\-instance\"\>([".TextRegex()."]*)\s*/", $url_value, $matches);
        $blogContent .= "<br>Reason For Creation: " . $matches[1]."<br>";
        preg_match("/([".TextRegex()."]*)\<\/gco\:CharacterString\>\<\/alternateTitle\>/", $url_value, $matches);
        $blogContent .= "<br>Dataset ID: ".$matches[1];
        preg_match("/([".TextRegex()."]*)\<\/gco\:CharacterString\>\<\/edition\>/", $url_value, $matches);
        $blogContent .= "<br>Version: " . $matches[1];
        preg_match("/([".TextRegex()."]*)\<\/gco\:CharacterString\>\<\/name\>\<\/CI_Series\>/", $url_value, $matches);
        $blogContent .= "<br>Serial-name/Serial-number: " . $matches[1];
        preg_match("/MD_ProgressCode\" codeListValue\=\"([".TextRegex()."]*)/", $url_value, $matches);
        $blogContent .= "<br>Progress of Dataset: " . $matches[1];
        
        
        preg_match("/\<date\>\<CI_Date\>\<date\>\<gco\:Date\>([0-9\-]*)\<\/gco\:Date\>\<\/date\>\<dateType\>\<CI_DateTypeCode codeList\=\"\.\/resources\/codeList\.xml\#CI_DateTypeCode\" codeListValue\=\"creation\"\/\>\<\/dateType\>\<\/CI_Date\>\<\/date\>\<date\>\<CI_Date\>\<date\>\<gco\:Date\>([0-9\-]*)\<\/gco\:Date\>\<\/date\>\<dateType\>\<CI_DateTypeCode codeList\=\"\.\/resources\/codeList\.xml\#CI_DateTypeCode\" codeListValue\=\"publication\"\/\>\<\/dateType\>\<\/CI_Date\>\<\/date\>\<date\>\<CI_Date\>\<date\>\<gco\:Date\>([0-9\-]*)\<\/gco\:Date\>\<\/date\>\<dateType\>\<CI_DateTypeCode codeList\=\"\.\/resources\/codeList\.xml\#CI_DateTypeCode\" codeListValue\=\"revision\"\/\>\<\/dateType\>\<\/CI_Date\>\<\/date\>/", $url_value, $matches);
        $blogContent .= "<br>Date of Creation: " . $matches[1];
        $blogContent .= "<br>Date of Publication: " . $matches[2];
        $blogContent .= "<br>Date of Revision: " . $matches[3];
        
        $blogContent .= "<br>";
        
        preg_match_all("/\<keyword\>\<gco\:CharacterString\>([".TextRegex()."]*)/", $url_value, $matches);
        $dataset_tags = $matches[1];
        preg_match("/([".TextRegex()."]*)\<\/gco\:CharacterString\>\<\/title\>\<date\>\<CI_Date\>\<date\>\<gco\:Date\>([0-9\-]*)/", $url_value, $matches);
        $blogContent .= "<br>Thesaurus Used: " . $matches[1];
        $blogContent .= "<br>Thesaurus Last Updated: " . $matches[2];
        
        $blogContent .= "<br>";
        preg_match("/MD_SpatialRepresentationTypeCode\" codeListValue\=\"([".TextRegex()."]*)/", $url_value, $matches);
        $blogContent .= "<br>Data Presented As: " . $matches[1];
        preg_match("/\<MD_RepresentativeFraction\>\<denominator\>\<gco\:Integer\>([0-9]*)/", $url_value, $matches);
        $blogContent .= "<br>Image of Map (in screenshots) scaled to: " . $matches[1];
        
        $blogContent .= "<br>";
        
        preg_match("/\<MD_Constraints\>\<useLimitation\>([".TextRegex()."]*)/", $url_value, $matches);
        $blogContent .= "<br>Restrictions/Gebruiksbeperkingen: " . $matches[1];
        preg_match_all("/\<otherConstraints\>\<gco\:CharacterString\>([".TextRegex()."]*)/", $url_value, $matches);
        foreach($matches[1] as $match_row)
        {
            $blogContent .= "<br>Other Restrictions/Overige beperkingen: " . $match_row;
        }
        preg_match("/MD_ClassificationCode\" codeListValue\=\"([".TextRegex()."]*)/", $url_value, $matches);
        $blogContent .= "<br>Security Restrictions/Veiligheidsrestricties: " . $matches[1];
        
        $blogContent .= "<br>";
        
        preg_match("/\#MD_CharacterSetCode\" codeListValue\=\"([".TextRegex()."]*)/", $url_value, $matches);
        $blogContent .= "<br>Character Coding: " . $matches[1];
        
        
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        //preg_match("/([".TextRegex()."]*)/", $url_value, $matches);
        //$blogContent .= "<br>Version: " . $matches[1];
        
        
    }
}

?>